/* eslint valid-jsdoc: "off" */

"use strict";
const path = require("path");

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1614435858412_3423";

  // add your middleware config here
  //config.middleware = ['m1', 'm2'];

  config.middleware = ["httpLog"];
  config.httpLog = {
    type: "all",
  };
  config.security = {
    csrf: {
      enable: false,
    },
  };

  config.auth = {
    exclude: ["/api/user/login", "/api/user/register"],
  };
  config.view = {
    mapping: {
      ".html": "ejs",
    },
    root: [
      path.join(appInfo.baseDir, "app/html"),
      path.join(appInfo.baseDir, "app/view"),
    ].join(","),
  };
  /* config.mysql = {
    app: true,
    agent: false,
    client: {
      host: '127.0.0.1',
      port: '3306',
      user: 'root',
      password: '12345678',
      database: 'egg_house'
    }
  } */
  config.static = {
    prefix: "/assets/",
    dir: path.join(appInfo.baseDir, "app/assets"),
  };
  config.ejs = {
    //delimiter: "$$"
  };
  // add your user config here
  const userConfig = {
    salt: "muke",
    redisExpire: 60 * 60 * 24,
  };
  config.session = {
    key: "Mic_SESS",
    httpOnly: true,
    maxAge: 1000 * 5,
    renew: true, // renew为true   当session为session最大缓存时间一半的时候，自动刷新session
  };
  config.sequelize = {
    dialect: "mysql",
    host: "127.0.0.1",
    port: "3306",
    user: "root",
    password: "12345678",
    database: "egg_house",
    define: {
      timestamps: false, // 时间不需要sequelize处理
      freezeTableName: true, // 表名称不需要sequelize来处理
    },
  };

  config.jwt = {
    secret: "muke",
  };
  config.redis = {
    client: {
      port: 6379,
      host: "127.0.0.1",
      password: "abc123456",
      db: 0,
    },
  };
  return {
    ...config,
    ...userConfig,
  };
};
